﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDay04__LINQ_
{
    public class Program
    {
        public static void Main(string[] args)
        {
            List<Book> books = new List<Book>() {
                new Book() { Title = "Game of Thrones: Everyone Dies", Author = "George R. R. Martin", Genre = "Children", Id = 1 },
                new Book() { Title = "Game of Thrones: Only Your Favorite Character Dies", Author = "George R. R. Martin", Genre = "Romance", Id = 2},
                new Book() { Title = "Game of Thrones: Really Nasty Stuff Happens", Author = "George R. R. Martin", Genre = "Fictional Documentary", Id = 3},
                new Book() { Title = "Game of Thrones: Why Is He Still Writing These?", Author = "George R. R. Martin", Genre = "Documentary", Id = 4},
                new Book() { Title = "Game of Thrones: Because He Is Making Tons Of Money", Author = "George R. R. Martin", Genre = "Sci-Fi", Id = 5},
                new Book() { Title = "Star Wars VII: Return of the Jar Jar", Author = "George Lucas", Genre = "Sci-Fi", Id = 6},
                new Book() { Title = "Star Wars VIII: Jar Jar Gets Stomped By An AT-AT", Author = "George Lucas", Genre = "Romance", Id = 7},
                new Book() { Title = "Indiana Jones: The Last Movie Harrison Ford Acts In", Author = "Disney", Genre = "Children", Id = 8},
                new Book() { Title = "Flubber Bounces Everywhere", Author = "Steven Spielburg", Genre = "Children", Id = 9},
                new Book() { Title = "Lord of the Bromance: Legolas and Gimli are BFFs", Author = "Tolkien", Genre = "Sci-Fi", Id = 10},
                new Book() { Title = "Harry Potter and the Year Griffindor did NOT Win The House Cup", Author = "J. K. Rowling", Genre = "History", Id = 11},
                new Book() { Title = "Die Hard 17: Finally Out of Bullets... Bring In The Grenades", Author = "Michael Bay", Genre = "Explosions", Id = 12}
            };
            foreach (var b in books)
            {
                if (b.Id < 7)
                {
                    b.PrintInfo(b.Id);
                }
                else if (b.Id < 10)
                {
                    b.PrintInfo("Jeremy");
                }
                else b.PrintInfo();
            }
            Console.ReadLine();


            Book book = new Book();
            book = books.FirstOrDefault(x => x.Id == 7);

            List<Book> OneToFourBooks = new List<Book>();

            OneToFourBooks = books.Where(x => x.Id >= 4 && x.Id <= 10).ToList();
            OneToFourBooks.ForEach(x => Console.WriteLine(x.Title + " " + x.Author + " " + x.Genre + " " + x.Id));

            List<Book> ExplodingMovies = new List<Book>();

            //string[] SyfyBoom = { "George Lucas", "Michael Bay" };
            ExplodingMovies = books.Where(x => x.Author.ToLower().Contains("george") || x.Author.ToLower().Contains("michael")).ToList();

            ExplodingMovies.ForEach(x => Console.WriteLine(x.Title + " " + x.Author + " " + x.Genre));

            Console.WriteLine(book.Title + " " + book.Author + " " + book.Genre);

            Console.ReadLine();
        }
    }


    public class Book
    {
        public string Title { get; set; }
        public string Genre { get; set; }
        public string Author { get; set; }
        public int Id { get; set; }

        //printing this book's information
        public void PrintInfo()
        {
            Console.WriteLine("{0} is written by {1} and the genre is {2}", this.Title, this.Author, this.Genre);
        }
        public void PrintInfo(string name)
        {
            Console.WriteLine("Hello {0}, you are reading {1}.", name, this.Title);
        }
        public void PrintInfo(int id)
        {
            Console.WriteLine("You have entered {0}");
        }
    }
}


/*
 * FirstOrDefault()
 * Where()
 * ToList()
 * OrderBy()
 * NOT NEEDED FOR NOW***** Select()
*/